#!/bin/bash

# 等待MySQL服务启动
echo "等待MySQL服务启动..."
while ! mysqladmin ping -h"localhost" -u"root" -p"$MYSQL_ROOT_PASSWORD" --silent; do
    sleep 2
done
echo "MySQL服务已启动！"

# 创建数据库
echo "创建数据库 hansoul_db..."
mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS hansoul_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

# 导入特定SQL文件
echo "开始导入SQL文件..."
for sql_file in /docker-entrypoint-initdb.d/sql-files/*.sql; do
    echo "导入文件: $(basename "$sql_file")"
    mysql -u root -p"$MYSQL_ROOT_PASSWORD" hansoul_db < "$sql_file"
done

echo "所有SQL文件导入完成！"